package edu.ynu.e_platform.service;

import edu.ynu.e_platform.common.service.LogicService;
import edu.ynu.e_platform.dao.ShopItemDao;
import edu.ynu.e_platform.entities.ShopItem;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

/**
 * @author manwen Yang
 */
@Slf4j
@Service
public class ShopItemService extends LogicService<ShopItemDao, ShopItem, Long> {
    public ShopItemService(@Autowired ShopItemDao lr) {
        super(lr);
    }

    /**
     * 查询所有上架的商品
     * */
    public List<ShopItem> queryAll(){

        try{
            return getDAO().findByItemStatus(1);

        }catch (Exception e){
            log.warn(e.toString());
        }
        return null;
    }

    public Page<ShopItem> PageQueryByItemStatus(Integer pageStart,Integer pageSize,Integer itemStatus){

        Pageable pageable = PageRequest.of(pageStart, pageSize, Sort.by("createTime").descending());

        return getDAO().find(itemStatus, pageable);
    }
}
